<?php 
	jimport('joomla.application.component.model');
	class sale_tsc_orderModelsu_luoc_ban_hang extends JModel
	{
	    //danh sach san pham order theo bill
        function ds_sp_bill($id_bill)
        {
            //echo $id_bill;
            $db = &JFactory::getDBO();
            $sql = "SELECT ep.name as pro_name, od.number, od.status
                    FROM #__erp_sale_order od, #__erp_product ep
                    WHERE od.id_order = '".$id_bill."'
                    AND ep.id = od.id_product
                ";
            $db->setQuery($sql);
            //print_r($db->loadObjectList());die;
            return $db->loadObjectList();    
        }

	    //tong tien trong ngay
        function tong_tien_trong_ngay()
        {
            $date = date('Y-m-d');
            $sql = "select sum(total) from #__erp_sale where id_employee= '".$_SESSION['id_user']."'
            AND date LIKE '$date%' AND  status = 4
            ";
            $db = &JFactory::getDBO();
            $db->setQuery($sql);
            $rs= $db->loadResult();
            return $rs;
        }
        
	    //tong tien tai cua hang
        function tong_tien_truoc_den_gio()
        {
            $sql = "select sum(total) from #__erp_sale where id_employee= '".$_SESSION['id_user']."' and status = 4";
            $db = &JFactory::getDBO();
            $db->setQuery($sql);
            $sum_truoc_den_gio = $db->loadResult();
            return $sum_truoc_den_gio;
        }
        //danh sach don hang theo ngay	   
		function ds_don_hang($date=null)
        {
            //neu date = null thi lay ngay hien hanh
            if($date == null)
            {
                $date = date('Y-m-d');
            }
            //dinh dang lai $date giong voi CSDL
            else
            {
                $d = substr($date,3,2);
                $m = substr($date,0,2);
                $y = substr($date,6,4);
                $date = $y."-".$m."-".$d;
                
            }
            $db = &JFactory::getDBO();
            $sql = "SELECT *
                    FROM #__erp_sale
                    WHERE date LIKE '$date%' 
                    AND del = 0
                    ORDER BY status ASC, date DESC
                ";
            $db->setQuery($sql);
            return $db->loadObjectList();
        }
        

	}
?>